package com.gzdh.dishrecognition.ui.adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.gzdh.dishrecognition.R;
import com.gzdh.dishrecognition.entity.BmcmEntity;
import com.gzdh.dishrecognition.model.WeekMenuBakModel;

import java.util.ArrayList;
import java.util.List;

public class SysWeekMenuAdapter extends RecyclerView.Adapter<SysWeekMenuAdapter.ViewHolder> {

    private Context mcontext;

    private List<WeekMenuBakModel.Product> list;



    public SysWeekMenuAdapter(Context context) {
        mcontext = context;
        this.list = new ArrayList<>();
    }


    public void setList(List<WeekMenuBakModel.Product> list) {
        this.list = list;
        notifyDataSetChanged();
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.view_string_gridview_item1, parent, false);
        return new ViewHolder(itemView);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {

        holder.nameTv.setText(list.get(position).getName().trim() + "     ￥" + list.get(position).getPrice());
//        holder.nameTv.setText(list.get(position).getName().trim() );

        if (position % 2 == 0) {
            holder.mainLinear.setBackgroundColor(Color.rgb(255, 255, 255));
        } else {
            holder.mainLinear.setBackgroundColor(Color.rgb(200, 200, 200));
        }

    }


    @Override
    public int getItemCount() {
        return list.size();
    }

    static class ViewHolder extends RecyclerView.ViewHolder {
        TextView nameTv;
        LinearLayout mainLinear;


        ViewHolder(View item) {
            super(item);
            nameTv = item.findViewById(R.id.nameTv);
            mainLinear = item.findViewById(R.id.mainLinear);

        }

    }


}
